<?php
/**
 *  💡 免责声明：本软件不得用于商业用途，仅做学习交流
 *  ⚠️ 权利声明：本软件由版权人提供产品技术支持
 *  📅 项目编号：NX2025-0135
 */
namespace App\Api\Controllers\Commons;

use App\Api\BaseApi;
use App\Models\Carousel;
use App\Models\Notice;

class OtherApi extends BaseApi
{
    /**
     * 轮播图.
     * @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\Routing\ResponseFactory|\Illuminate\Http\Response
     */
    public function carousels()
    {
        $type = request('type', 1);
        $res = Carousel::query()
            ->where('is_active', 1)
            ->where('type', $type)
            ->orderByDesc('order')
            ->get();
        return responses($res);
    }

    public function notice()
    {
        $res = Notice::query()
            ->select('id', 'title', 'type', 'is_pinned', 'publish_at')
            ->where('is_active', 1)
            ->where(function ($q) {
                $q->whereNull('expire_at')
                    ->orWhere('expire_at', '>', now());
            })->get();
        return responses($res);
    }

    public function noticeDetails()
    {
        $request = self::validate([
            'id' => 'required|integer',
        ]);
        $res = Notice::query()->findOrFail($request['id']);
        return responses($res);
    }
}
